<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <h1>你好,练习</h1>
    <p>
      <router-link to='/foo'>展示foo</router-link>
      <router-link to='/bar'>展示bar</router-link>
    </p>
    <router-view></router-view>
  </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 引入VueRouter -->
<script src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script>
  Vue.component('foo',{
    template:`<div> 你好,我是foo组件</div>`
  });
  Vue.component('bar',{
    template:`<div> 你好,我是bar组件</div> `,
    computed: {
      getUserName(){
        return $route.params.username
      }
    },
    methods: {
      goBack(){
        window.history.length >1 ? this.router.go(-1) : this.router.push('/')
      }
    },
  });
   var routes = [
     {path:'/',component:'foo'},
     {path:'/foo',component:'foo'},
     {path:'/bar',component:'bar'}
   ]
   const router = new VueRouter({
     routes
  });
  var app = new Vue({
    el:'#app',
    router
  });
  
</script>
</html>